package com.jame.concurrency.cas;

/**
 * @author : Jame
 * @date : 2021-07-10 16:53
 **/
public class ConcurrencyDemo {


    public static void main(String[] args) throws InterruptedException {

        long startTime=System.currentTimeMillis();

        A a = new A();

        Thread thread = new Thread(() -> {
            for (int i = 0; i < 100000000; i++) {
                a.addCAS();
            }
        });

        thread.start();

        for (int i = 0; i < 100000000; i++) {
            a.addCAS();
        }
        thread.join();

        System.out.println(a.getCAS());




        long endTime=System.currentTimeMillis();

        System.out.println("程序运行时间： "+(endTime-startTime)+"ms");
    }
}

/**
 *   int i=0;
 *
 *         int oldValue=i;
 *
 *         int newValue=i++;
 *
 *         if(i==oldValue){
 *             i=newValue;
 *         }
 */
